package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.ujoku.dao.MemberBalanceLogDao;
import com.ujoku.dao.MyListItemDao;
import com.ujoku.domain.MemberBalanceLog;
import com.ujoku.domain.MemberBalanceLogStatus;
import com.ujoku.domain.MemberBalanceLogType;
import com.ujoku.domain.MyListItem;
import com.ujoku.service.CdnService;
import com.ujoku.service.MemberBalanceLogService;
import com.ujoku.service.MyListItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 14-10-19.
 */
@Service
public class MemberBalanceLogImpl extends BaseServiceImpl<MemberBalanceLog> implements MemberBalanceLogService<MemberBalanceLog> {

    @Autowired
    private MemberBalanceLogDao dao;

    @Override
    protected BaseDao<MemberBalanceLog> getBaseDao() {
        return dao;
    }


    @Override
    public Double getChargeTotalByMemberId(int memberId){

        Map<String,Object> query = new HashMap<>();
        query.put("memberId",memberId);
        query.put("type", MemberBalanceLogType.RECHARGE);
        query.put("status", MemberBalanceLogStatus.DONE);
        List<MemberBalanceLog> list =  this.selectList(query);

        if(list.size() == 0)
            return null;

        return list.stream().mapToDouble(p -> p.getAmount()).sum();
    }

    @Override
    public List<MemberBalanceLog> selectListByMember(Map<String, Object> query){
        return dao.selectListByMember(query);
    }

}
